package com.ukao.cashregister.pesenter;

import android.content.Context;

import com.ukao.cashregister.base.BasePresenter;
import com.ukao.cashregister.bean.OrderQuiryTabeleBean;
import com.ukao.cashregister.bean.ReceiptBean;
import com.ukao.cashregister.bean.StringBean;
import com.ukao.cashregister.consts.Constant;
import com.ukao.cashregister.consts.SaveParamets;
import com.ukao.cashregister.retrofit.ApiCallback;
import com.ukao.cashregister.utils.Utils;
import com.ukao.cashregister.view.OrderQuiryView;

import java.util.HashMap;

/**
 * Created by ukaodev on 2017/6/26.
 */

public class OrderQuiryPesenter extends BasePresenter<OrderQuiryView> {

    public OrderQuiryPesenter(OrderQuiryView view) {
        attachView(view);
    }






    /**
     *获取用户信息
     */
    public void qrderQuiryData(Context  context,int  page,int pagesize,String startCreateTime,String endCreateTime,String payStatus,String statusVal,String  searchValue  ) {

        HashMap     mHashMap=new HashMap<String,String>();
        if (!searchValue.isEmpty()){
            startCreateTime="";
            endCreateTime="";
        }
        mHashMap.put("startCreateTime",startCreateTime);
        mHashMap.put("endCreateTime",endCreateTime);
        mHashMap.put("payStatus",payStatus);
        mHashMap.put("statusVal",statusVal);
        mHashMap.put("pageNum",page+"");
        mHashMap.put("pageSize",pagesize+"");
        mHashMap.put("accessToken", SaveParamets.getToken(context));
        mHashMap.put("searchValue", searchValue);


        addSubscription(apiStores.qrderQuiry(Constant.createParameter(mHashMap)),
                new ApiCallback<OrderQuiryTabeleBean>() {
                    @Override
                    public void onSuccess(OrderQuiryTabeleBean model) {
                        if (model.getHttpCode()==200){
                            mvpView.getDataSuccess(model.getData().getList(),model.getData().getPages());
                        }else{
                             mvpView.loadFail(model.getMsg());
                        }


                   }



                    @Override
                    public void onFinish() {

                    }

                });
    }


    /**
     *订单作废
     */

    public void orderInfoDestroy(Context context, String  id,String remark) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("id",id);
        mHashMap.put("remark",remark);/*作废备注*/
        mHashMap.put("accessToken", SaveParamets.getToken(context));
        addSubscription(apiStores.orderInfoDestroy(Constant.createParameter(mHashMap)),
                new ApiCallback<StringBean>() {
                    @Override
                    public void onSuccess(StringBean model) {
                        if (model.getHttpCode()==200){
                           mvpView.loadOrderInfoDestroy(model.getMsg());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }


                    }



                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }

    /**
     *备注
     */
    public void addRemark(Context context, String  id,String remark) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("id",id);
        mHashMap.put("remark",remark);/*备注*/
        mHashMap.put("accessToken", SaveParamets.getToken(context));
        addSubscription(apiStores.remark(Constant.createParameter(mHashMap)),
                new ApiCallback<StringBean>() {
                    @Override
                    public void onSuccess(StringBean model) {
                        if (model.getHttpCode()==200){
                            mvpView.loadAddRemark(model.getMsg());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }


                    }



                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }
    /**
     *打印订单
     */
    public void printReceipt(Context context, String  id ) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("orderId",id);
        mHashMap.put("accessToken", SaveParamets.getToken(context));
        addSubscription(apiStores.printReceipt(Constant.createParameter(mHashMap)),
                new ApiCallback<ReceiptBean>() {
                    @Override
                    public void onSuccess(ReceiptBean model) {
                        if (model.getHttpCode()==200){
                            mvpView.loadReceipt(model.getData());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }


                    }



                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }


    /**
     *

     修改工厂运单号
     * @param mListData item
     * @param transNo  工厂运单号
     */
    public void updateFactoryTransNo( final  OrderQuiryTabeleBean.ListBean   mListData,final String  transNo ) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("orderId",mListData.getId());/*订单衣物id*/
        mHashMap.put("transNo",transNo);
        mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
        addSubscription(apiStores.updateFactoryTransNo(Constant.createParameter(mHashMap)),
                new ApiCallback<StringBean>() {
                    @Override
                    public void onSuccess(StringBean model) {
                        if (model.getHttpCode()==200){
                            mListData.setFactoryTransNo(transNo);
                            mvpView.updateFactorySucceed(mListData);
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }


                    }



                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }


    
}
